package com.itheima.test3;

public class Test3Polymorpic {
    public static void main(String[] args) {
        useAnimal(new Dog());
        useAnimal(new Cat());
    }
    public static void useAnimal(Animal a){  //Animal a = new Dog();
                                             //Animal a = new Cat();
        a.eat();

        if (a instanceof Dog){
            Dog d =(Dog)a;
            d.method();
        }

    }

}


abstract class Animal{
    public abstract void eat();
}

class Dog extends Animal{

    @Override
    public void eat() {
        System.out.println("狗吃肉");
    }

    public void method() {
        System.out.println("method");
    }
}

class Cat extends Animal{

    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }
}